#include<iostream>

using namespace std;

//-----------------------

//非类型模板参数

template<class T,int N>//T为类型模板参数，N为非类型模板参数
//一般来说 类型模板参数后面跟的都是类型，而一般非类型模板参数后面一般为整型常量（包括int/char/short/long/long long等）
class Array{
  
  T _a[N];

};

void test_1(){

  Array<int,10> _a1;
  Array<double,20> _a2;

}

//------------------------

//模板的特化

//全特化

/*template<class T>
struct Less{
  bool operator()(const T&a,const T&b){
    return a<b;
  }
};*/

/*template<>
struct Less<int*>{
  bool operator()(const int *a,const int *b){
    return *a<*b;
  }
};*/

void test_2(){
  int a = 10,b = 20;
 // Less<int> lessfunc;
 //cout<<lessfunc(a,b)<<endl;
 // Less<int*> lessfunc1;
 // cout<<lessfunc1(&a,&b)<<endl;

}

//--------------------
//偏特化

template<class T>
struct Less{
  bool operator()(const T&a,const T&b){
    return a<b;
  }
};

template<class T>
struct Less<T*>{
  bool operator()(const T*a,const T*b)const{
    return *a<*b;
  }
};

void test_3(){
  int a = 10;
  int b = 20;

  cout<<Less<int>()(a,b)<<endl;
  cout<<Less<int*>()(&a,&b)<<endl;

}

//----------------------------
//部分特化与全特化

template<class T1,class T2>
void Print(T1 a,T2 b){
  cout<<"T1,T2"<<endl;
  cout<<"原模板"<<endl;
}

template<class T1>
void Print(T1 a,int* b){
  cout<<"T1,int*"<<endl;
  cout<<"全特化"<<endl;
}

template<class T1,class T2>
void Print(T1 a,T2* b){
  cout<<"T1,T2*"<<endl;
  cout<<"偏特化"<<endl;
}


template<class T1>
void Print(T1* a,char* b){
  cout<<"T1*,char*"<<endl;
  cout<<"全特化+偏特化"<<endl;
}

void test_4(){

  int a = 10;
  int b = 20;
  double c = 2.2;
  char d = 's';
  Print(a,b);
  Print(a,&b);
  Print(a,&c);
  Print(&c,&d);

}

int main()
{
//test_2();
//test_3();
test_4();


  return 0;
}
